package com.ilearn.spring.future.dto;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;

import javax.servlet.AsyncContext;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Project: edb-core
 * @Description:
 * @Version 1.0
 * @Throws SystemException:
 * @Author: <li>2018/8/10 lyndon Create 1.0
 * @Copyright (c)2018-2018 中央结算公司，版权所有
 * @Modified By:
 */
@Data
@AllArgsConstructor
@Builder
public class AsyncHttpEvent implements IEvent {
   private AsyncContext asyncContext;
   private HttpServletResponse response;

   @Override
   public ServletRequest getRequest() {
      return asyncContext.getRequest();
   }

   @Override
   public ServletResponse getResponse() {

      if (response == null) {
         throw new IllegalStateException(
                 "AsyncHttpEvent response is null.");
      }
      return response;
   }

   @Override
   public void complete() {
      this.asyncContext.complete();
   }
}
